//获取应用实例
import network from '../../utils/network.js';
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    select: 1,
    tihuoWay: '2018',
    tihuoyue: '9',
    uid: 0,
    userInfo: [],
    isHiddenToast: true,
    page: 1,
    rows: 10,
    total: 0,
    hasMoreData: true,
    list: [],
    Inx: 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    const id = options.id; 
    that.setData({
      uid: id,
    });
    that.getOrder_list('正在加载数据...')
    // 页面初始化 options为页面跳转所带来的参数
  },

  //切换选择
  selectTap:function(e){
    var that = this;
    var select = e.target.dataset.id; 
   that.setData({
     select: select,
     page:1,
     list:[],
   });
    that.getOrder_list("正在加载中");
    
  },
//1
  bindShowMsg() {
    this.setData({
      select: !this.data.select
    })
  },
  mySelect(e) {
    var name = e.currentTarget.dataset.name
    this.setData({
      tihuoWay: name,
      select: false
    })
  },


// 2
  bindShowyue() {
    this.setData({
      select1: !this.data.select1
    })
  },
  mySelect1(e) {
    var name = e.currentTarget.dataset.name
    this.setData({
      tihuoyue: name,
      select1: false
    })
  },


// 查看客户资料
  seeCustomer:function(e){ 
    var id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/view/customer_data/customer_data?id=' + id,
    });
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  // 获取用户列表
  getOrder_list: function (message) {
    var that = this; 
    var datas = that.data; 
    var data = {
      order_type: datas.select,
      uid: that.data.uid,
      ischeck: 1,
      page: datas.page,
      rows: datas.rows
    };
    network.requestLoading('http://jbc.com/System/Order/order_list', data, message, function (res) {
       
      var contentlistTem = that.data.list;
      if (res.code > 0) {
        if (contentlistTem.length < res.data.total) {
          that.setData({
            page: datas.page + 1,
            list: res.data.list,
          });
        } else {
          that.setData({
            hasMoreData: false
          });
        }

      } else {
        wx.showToast({
          title: res.msg,
        })
      }
    }, function (res) {
      wx.showToast({
        title: '加载数据失败',
      })

    })
  },
  /**
 * 页面相关事件处理函数--监听用户下拉动作
 */
  onPullDownRefresh: function () {
    this.data.page = 1;
    this.getSale_list('正在刷新数据')
    console.log("下拉加载更多")
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    console.log("下滑加载更多")
    if (this.data.hasMoreData) {
      this.getSale_list('加载更多数据');
    } else {
      console.log("没有更多的数据")
      wx.showToast({
        title: '没有更多数据',
      })
    }
  },
})
